
#include <Windows.h>
#include "HealthBar.h"
#include <GL\GL.h>

HealthBar::HealthBar(float maxHealth, float x, float y, float w, float h)
{
	if(maxHealth == 0)
	{
		maxHealth = 1;
	}
	_maxHealth = maxHealth;
	_x = x;
	_y = y;
	_w = w;
	_h = h;
}

HealthBar::~HealthBar()
{

}

void HealthBar::Render(float health)
{
	float hw = health/_maxHealth * _w;
	float nx = _x + hw;
	float nw = _w - hw;
	glBegin(GL_QUADS);
		glColor3f(1.0f, 0.0f, 0.0f);
		glVertex2f(nx, _y);
		glColor3f(0.6f, 0.0f, 0.0f);
		glVertex2f(nx, _y + _h);
		glVertex2f(nx + nw, _y + _h);
		glColor3f(1.0f, 0.0f, 0.0f);
		glVertex2f(nx + nw, _y);

		glColor3f(0.0f, 1.0f, 0.0f);
		glVertex2f(_x, _y);
		glColor3f(0.0f, 0.3f, 0.0f);
		glVertex2f(_x, _y + _h);
		glVertex2f(_x + hw, _y + _h);
		glColor3f(0.0f, 1.0f, 0.0f);
		glVertex2f(_x + hw, _y);
	glEnd();
}
